package com.cn.xly2023.controller;


import com.cn.xly2023.pojo.Good;
import com.cn.xly2023.pojo.PageBean;
import com.cn.xly2023.pojo.Result;
import com.cn.xly2023.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodController {
    @Autowired
    private GoodService goodService;
    @GetMapping
    public Result getList(@RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "10") Integer pageSize,String goodName,Integer delete_status,Integer status){
        PageBean pageBean = (PageBean) goodService.selectall(page,pageSize,goodName,delete_status,status);
        return Result.success(pageBean);
    }

    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids) {
        goodService.deleteByIds(ids);
        return Result.success();
    }

    @PostMapping
    public Result insertGood(Good good){
        goodService.insertGood(good);
        return Result.success(good);
    }

    @PutMapping
    public Result updateGood(Good good){
        goodService.updateGood(good);
        return Result.success(good);
    }




}
